package STUDENT.NGUYENHUUTHANG.STRUCTURE_PROGRAMMING.EXAMPLES;

import java.util.Scanner;

public class tam_giac {

	public static void main(String[] args) {
		String side1 = "";
		String side2 = "";
		String side3 = "";
		double a = 0;
		double b = 0;
		double c = 0;
		System.out.println("Ban hay nhap vao 3 canh cua tam giac");
		do {
			System.out.println("side 1 = ");
			Scanner sc = new Scanner(System.in);
			side1 = sc.nextLine();
			if (side1.isEmpty()) {
				System.out.println("Ban chua nhap!");
			} else {
				a = Double.parseDouble(side1);
				if (a <= 0) {
					System.out.println("Ban phap nhap mot so lon hon 0!");

				}
			}

		} while (side1.isEmpty() || a <= 0);
		do {
			System.out.println("side 2 = ");
			Scanner sc = new Scanner(System.in);
			side2 = sc.nextLine();
			if (side2.isEmpty()) {
				System.out.println("Ban chua nhap!");
			} else {
				b = Double.parseDouble(side2);
				if (b <= 0) {
					System.out.println("Ban phap nhap mot so lon hon 0!");

				}
			}

		} while (side2.isEmpty() || b <= 0);
		do {
			System.out.println("side 3 = ");
			Scanner sc = new Scanner(System.in);
			side3 = sc.nextLine();
			if (side3.isEmpty()) {
				System.out.println("Ban chua nhap!");
			} else {
				c = Double.parseDouble(side3);
				if (c <= 0) {
					System.out.println("Ban phap nhap mot so lon hon 0!");

				}
			}

		} while (side2.isEmpty() || c <= 0);
		if (a+b>c && a+c>b && b+c>a){
			double P = a+b+c;
			System.out.println("Chu vi tam giac la: " + P);
			double p=P/2;
			double S = Math.sqrt(p*(p-a)*(p-b)*(p-c));
			System.out.println("Dien tich tam giac la: " + S);
		} else System.out.println("Ban nhap 3 canh khong thoa man mot tam giac!");
	}

}
